package com.practice.dataStructure.tree;

import java.util.ArrayList;

public class BinaryTree<E> {
    //链式存储
    private BinaryTreeNode<E> root;

    //树形数组存储
    private ArrayList<E> binaryTree;

    public BinaryTree(){
        binaryTree = new ArrayList<>();
    }

    //先序遍历
    public void preOrder(BinaryTreeNode<E> root){
        if(root == null){
            return;
        }
        System.out.println(root.getData());
        preOrder(root.getLeftChild());
        preOrder(root.getRightChild());
    }
    //中序遍历
    public void inOrder(BinaryTreeNode<E> root){
        if(root == null){
            return;
        }
        inOrder(root.getLeftChild());
        System.out.println(root.getData());
        inOrder(root.getRightChild());
    }
    //后序遍历
    public void postOrder(BinaryTreeNode<E> root){
        if(root == null){
            return;
        }
        postOrder(root.getLeftChild());
        postOrder(root.getRightChild());
        System.out.println(root.getData());
    }
}
